<?php
include('./include/conn.php');
$add['title'] = trim($_POST['title']);
$add['author'] = trim($_POST['author']);
$add['content'] = htmlspecialchars(trim($_POST['content']));
$add['time'] = date('Y-m-d H:i:s');

//var_dump($add);
//查询是否有相同标题 
$query = "SELECT * FROM msg WHERE `title` = '".$add['title']."'";
//echo $query;
$rs = $link->query($query);
if ($rs->num_rows) {
	 echo"<script>alert('标题已经存在，请重新输入！');window.history.go(-1);</script>";
}else{
	$query="INSERT INTO msg VALUES(null,'$add[title]','$add[author]','$add[content]','$add[time]',0,0)";
	if ($link->query($query)) {
		 echo "<script>alert('添加话题成功！'); window.location.href='index.php';</script>";
	}else{
		echo"<script>alert('数据写入失败！'); window.history.go(-1);</script>";
	}
}
?>